import {Inject, Injectable} from '@nestjs/common';
import {MongoRepository} from "typeorm";
import {Category} from "./model/mongo/book/category.entity";
import {Books} from "./model/mongo/book/books.entity";
import {IMongoFind} from "./util/database.query.interface";
import {Message} from "./model/mongo/tao/message.entity";

@Injectable()
export class AppService {
  constructor(
      @Inject('categoryModelToken')
      private readonly categoryModel: MongoRepository<Category>,
      @Inject('booksModelToken')
      private readonly booksModel: MongoRepository<Books>,
      @Inject('messageModelToken')
      private readonly messageModel: MongoRepository<Message>,
  ) {
  }

  getHello(): string {
    return 'Hello World!33';
  }

  getCategoryNameList(param?: IMongoFind): Promise<Category[]> {
    let res = this.categoryModel.find();

    return res;
  }
  getBookList(param?: IMongoFind): Promise<Books[]> {
    let res = this.booksModel.find({
      take: 10,
      select: ["title"],
      order: {
        title: "ASC"
      }
    });

    return res;
  }
  getMessageList(param?: IMongoFind): Promise<Message[]> {
    let res = this.messageModel.find({
      take: 1
    });

    return res;
  }
}
